<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.focusmedia.central.${appCode}.tunnel.mapper${dataSource}.${modelPackName}.${className}QueryMapper">
    <resultMap id="BaseResultMap" type="cn.focusmedia.central.${appCode}.tunnel.dataobject.${modelPackName}.${className}DO">
        ${resultMap}
    </resultMap>

    <sql id="ALL_COLUMNS">
        ${columnFileds}
    </sql>

    <sql id="FROM_TABLE">
        FROM ${tableNameWithAlias}
    </sql>

    <sql id="COMMON_SELECT">
        SELECT
        <include refid="ALL_COLUMNS"/>
        <include refid="FROM_TABLE"/>
    </sql>

    <sql id="COMMON_COUNT">
        SELECT
        count(1)
        <include refid="FROM_TABLE"/>
    </sql>

    <sql id="COMMON_WHERE">
        <where>
${whereFileds}
        </where>
    </sql>

    <select id="query" parameterType="map" resultMap="BaseResultMap">
        <bind name="offset" value="(pageNum-1)*pageSize"></bind>
        <include refid="COMMON_SELECT"/>
        <include refid="COMMON_WHERE"/>
        <if test="pageSize>0">
${pageFileds}
        </if>
    </select>

    <select id="count" parameterType="map" resultType="java.lang.Integer">
        <include refid="COMMON_COUNT"/>
        <include refid="COMMON_WHERE"/>
    </select>

</mapper>